package com.example.basic.utils;

import okhttp3.Response;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class HttpClientUtils {
    public static void main(String[] args) {
        String url = "http://open.tuhugc.com";

        String tokenUrl = "/v1/token/get";
        Map<String,String> map = new HashMap<String,String>();
        map.put("timestamp","2023-03-07 17:18:00");
        map.put("appKey","51726c687d5236f9131dacfdb1b37832");
        map.put("signMethod","md5");
        map.put("format","json");
        map.put("v","1.0");
        map.put("userId","18810268239");
        map.put("expiresIn","7200");
        try {
            String s = MD5Test.signTuhuRequest(map, "e73c37d23c1e99dfb071b0ca88505bd9", "md5");
            map.put("sign",s);
            Response response = HttpUtils.get(url + tokenUrl, map);
            Map<String, Object> stringObjectMap = JsonUtils.toMap(response.body().string());
            System.out.println(stringObjectMap);
        } catch (IOException e) {
            throw new RuntimeException(e);
        } catch (Exception e) {
            throw new RuntimeException(e);
        }

    }

}
